<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 商品闪购操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * @create by allen.qiang
 */
require 'module/base/promotion/goodsSpecial.class.php';

class pa_goodsSpecial{

    public function execute() {

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg'])) {
            switch ($_REQUEST['operFlg']) {
                case 1:                 //商品特价列表
                    $this->goodsSpecialList();
                    break;

                case 2:                 //商品特价保存编辑
                    $this->goodsSpecialEdit();
                    break;

                default:
                    $this->toError( '参数错误' );
                    break;
            }
        } else {
            $this->toError( '参数错误' );
        }

    }

    /**
     * 转跳到错误页面
     * @param string $msg 错误信息
     */
    private function toError( $msg ) {
        global $G_PGLOB;
        $G_PGLOB->display_error_page( $msg );
    }

    /**
     * 商品特价列表
     */
    private function goodsSpecialList() {

        global $G_PGLOB;

        $G_PGLOB->smarty->display('promotion/goodsSpecialList.tpl');
    }

    /**
     * 商品特价保存编辑
     */
    private function goodsSpecialEdit(){

        global $G_PGLOB;

        $goodsSpecial = new goodsSpecial($G_PGLOB->DBCA);

        $startTime = array();

        for($i=0;$i<24;$i++){

            if($i<10){
                $val = '0'.$i;
            }else{
                $val = $i;
            }

            $startTime[] = $val;

        }

        //特价编辑
        if(isset($_REQUEST['promotionID']) && !empty($_REQUEST['promotionID'])){

            //判断当前是否在活动时间内
            $time = date('Y-m-d H:i:s');

            $promotion = $goodsSpecial->searchGoodsSpecialList($_REQUEST);

            $starttotime = $promotion[0]['startDate'].' 00:00:00';

            $endtotime = $promotion[0]['endDate'].' 23:59:59';

            if($time >= $starttotime && $time <= $endtotime){
                $this->toError('当前正在活动期间内，禁止修改该活动');
            }

            $arg['promotionID'] = $_REQUEST['promotionID'];

            $promotion = $goodsSpecial->searchGoodsSpecialList($arg);

            $G_PGLOB->smarty->assign_by_ref('promotion',$promotion[0]);

        }

        $G_PGLOB->smarty->assign_by_ref('startTime',$startTime);

        $G_PGLOB->smarty->display('promotion/goodsSpecialEdit.tpl');

    }

}